<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="开始时间" prop="startDatetime">
        <el-date-picker clearable
          v-model="queryParams.startDatetime"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择开始时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="结束时间" prop="endDatetime">
        <el-date-picker clearable
          v-model="queryParams.endDatetime"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择结束时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="创建时间" prop="createDatetime">
        <el-date-picker clearable
          v-model="queryParams.createDatetime"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择创建时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="收银员ID" prop="cashierId">
        <el-input
          v-model="queryParams.cashierId"
          placeholder="请输入收银员ID"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="发票数量" prop="invoiceNum">
        <el-input
          v-model="queryParams.invoiceNum"
          placeholder="请输入发票数量"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="紧急发票数量" prop="rushInvoiceNum">
        <el-input
          v-model="queryParams.rushInvoiceNum"
          placeholder="请输入紧急发票数量"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="重印发票数量" prop="reprintInvoiceNum">
        <el-input
          v-model="queryParams.reprintInvoiceNum"
          placeholder="请输入重印发票数量"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="开始和结束发票ID字符串" prop="startEndInvoiceIdStr">
        <el-input
          v-model="queryParams.startEndInvoiceIdStr"
          placeholder="请输入开始和结束发票ID字符串"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="紧急发票ID列表字符串" prop="rushInvoiceIdListStr">
        <el-input
          v-model="queryParams.rushInvoiceIdListStr"
          placeholder="请输入紧急发票ID列表字符串"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="重印发票ID列表字符串" prop="reprintInvoiceIdListStr">
        <el-input
          v-model="queryParams.reprintInvoiceIdListStr"
          placeholder="请输入重印发票ID列表字符串"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="药品金额" prop="medicineAmount">
        <el-input
          v-model="queryParams.medicineAmount"
          placeholder="请输入药品金额"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="中药金额" prop="herbalAmount">
        <el-input
          v-model="queryParams.herbalAmount"
          placeholder="请输入中药金额"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="检查金额" prop="checkAmount">
        <el-input
          v-model="queryParams.checkAmount"
          placeholder="请输入检查金额"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="处置金额" prop="dispositionAmount">
        <el-input
          v-model="queryParams.dispositionAmount"
          placeholder="请输入处置金额"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="登记金额" prop="registrationAmount">
        <el-input
          v-model="queryParams.registrationAmount"
          placeholder="请输入登记金额"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="测试金额" prop="testAmount">
        <el-input
          v-model="queryParams.testAmount"
          placeholder="请输入测试金额"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="总金额" prop="amount">
        <el-input
          v-model="queryParams.amount"
          placeholder="请输入总金额"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="现金金额" prop="cashAmount">
        <el-input
          v-model="queryParams.cashAmount"
          placeholder="请输入现金金额"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="保险金额" prop="insuranceAmount">
        <el-input
          v-model="queryParams.insuranceAmount"
          placeholder="请输入保险金额"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="银行卡金额" prop="bankCardAmount">
        <el-input
          v-model="queryParams.bankCardAmount"
          placeholder="请输入银行卡金额"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="支付宝金额" prop="alipayAmount">
        <el-input
          v-model="queryParams.alipayAmount"
          placeholder="请输入支付宝金额"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="微信金额" prop="wechatAmount">
        <el-input
          v-model="queryParams.wechatAmount"
          placeholder="请输入微信金额"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="信用卡金额" prop="creditCardAmount">
        <el-input
          v-model="queryParams.creditCardAmount"
          placeholder="请输入信用卡金额"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="其他金额" prop="otherAmount">
        <el-input
          v-model="queryParams.otherAmount"
          placeholder="请输入其他金额"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="审核操作员ID" prop="verifyOperatorId">
        <el-input
          v-model="queryParams.verifyOperatorId"
          placeholder="请输入审核操作员ID"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="审核时间" prop="verifyDatetime">
        <el-date-picker clearable
          v-model="queryParams.verifyDatetime"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择审核时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['bms:operatorSettleRecord:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['bms:operatorSettleRecord:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['bms:operatorSettleRecord:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['bms:operatorSettleRecord:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="operatorSettleRecordList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="主键" align="center" prop="id" />
      <el-table-column label="开始时间" align="center" prop="startDatetime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.startDatetime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="结束时间" align="center" prop="endDatetime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.endDatetime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="创建时间" align="center" prop="createDatetime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.createDatetime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="收银员ID" align="center" prop="cashierId" />
      <el-table-column label="发票数量" align="center" prop="invoiceNum" />
      <el-table-column label="紧急发票数量" align="center" prop="rushInvoiceNum" />
      <el-table-column label="重印发票数量" align="center" prop="reprintInvoiceNum" />
      <el-table-column label="开始和结束发票ID字符串" align="center" prop="startEndInvoiceIdStr" />
      <el-table-column label="紧急发票ID列表字符串" align="center" prop="rushInvoiceIdListStr" />
      <el-table-column label="重印发票ID列表字符串" align="center" prop="reprintInvoiceIdListStr" />
      <el-table-column label="药品金额" align="center" prop="medicineAmount" />
      <el-table-column label="中药金额" align="center" prop="herbalAmount" />
      <el-table-column label="检查金额" align="center" prop="checkAmount" />
      <el-table-column label="处置金额" align="center" prop="dispositionAmount" />
      <el-table-column label="登记金额" align="center" prop="registrationAmount" />
      <el-table-column label="测试金额" align="center" prop="testAmount" />
      <el-table-column label="总金额" align="center" prop="amount" />
      <el-table-column label="现金金额" align="center" prop="cashAmount" />
      <el-table-column label="保险金额" align="center" prop="insuranceAmount" />
      <el-table-column label="银行卡金额" align="center" prop="bankCardAmount" />
      <el-table-column label="支付宝金额" align="center" prop="alipayAmount" />
      <el-table-column label="微信金额" align="center" prop="wechatAmount" />
      <el-table-column label="信用卡金额" align="center" prop="creditCardAmount" />
      <el-table-column label="其他金额" align="center" prop="otherAmount" />
      <el-table-column label="审核操作员ID" align="center" prop="verifyOperatorId" />
      <el-table-column label="审核时间" align="center" prop="verifyDatetime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.verifyDatetime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="审核状态" align="center" prop="verifyStatus" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['bms:operatorSettleRecord:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['bms:operatorSettleRecord:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改收费员日结对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="开始时间" prop="startDatetime">
          <el-date-picker clearable
            v-model="form.startDatetime"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择开始时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="结束时间" prop="endDatetime">
          <el-date-picker clearable
            v-model="form.endDatetime"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择结束时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="创建时间" prop="createDatetime">
          <el-date-picker clearable
            v-model="form.createDatetime"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择创建时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="收银员ID" prop="cashierId">
          <el-input v-model="form.cashierId" placeholder="请输入收银员ID" />
        </el-form-item>
        <el-form-item label="发票数量" prop="invoiceNum">
          <el-input v-model="form.invoiceNum" placeholder="请输入发票数量" />
        </el-form-item>
        <el-form-item label="紧急发票数量" prop="rushInvoiceNum">
          <el-input v-model="form.rushInvoiceNum" placeholder="请输入紧急发票数量" />
        </el-form-item>
        <el-form-item label="重印发票数量" prop="reprintInvoiceNum">
          <el-input v-model="form.reprintInvoiceNum" placeholder="请输入重印发票数量" />
        </el-form-item>
        <el-form-item label="开始和结束发票ID字符串" prop="startEndInvoiceIdStr">
          <el-input v-model="form.startEndInvoiceIdStr" placeholder="请输入开始和结束发票ID字符串" />
        </el-form-item>
        <el-form-item label="紧急发票ID列表字符串" prop="rushInvoiceIdListStr">
          <el-input v-model="form.rushInvoiceIdListStr" placeholder="请输入紧急发票ID列表字符串" />
        </el-form-item>
        <el-form-item label="重印发票ID列表字符串" prop="reprintInvoiceIdListStr">
          <el-input v-model="form.reprintInvoiceIdListStr" placeholder="请输入重印发票ID列表字符串" />
        </el-form-item>
        <el-form-item label="药品金额" prop="medicineAmount">
          <el-input v-model="form.medicineAmount" placeholder="请输入药品金额" />
        </el-form-item>
        <el-form-item label="中药金额" prop="herbalAmount">
          <el-input v-model="form.herbalAmount" placeholder="请输入中药金额" />
        </el-form-item>
        <el-form-item label="检查金额" prop="checkAmount">
          <el-input v-model="form.checkAmount" placeholder="请输入检查金额" />
        </el-form-item>
        <el-form-item label="处置金额" prop="dispositionAmount">
          <el-input v-model="form.dispositionAmount" placeholder="请输入处置金额" />
        </el-form-item>
        <el-form-item label="登记金额" prop="registrationAmount">
          <el-input v-model="form.registrationAmount" placeholder="请输入登记金额" />
        </el-form-item>
        <el-form-item label="测试金额" prop="testAmount">
          <el-input v-model="form.testAmount" placeholder="请输入测试金额" />
        </el-form-item>
        <el-form-item label="总金额" prop="amount">
          <el-input v-model="form.amount" placeholder="请输入总金额" />
        </el-form-item>
        <el-form-item label="现金金额" prop="cashAmount">
          <el-input v-model="form.cashAmount" placeholder="请输入现金金额" />
        </el-form-item>
        <el-form-item label="保险金额" prop="insuranceAmount">
          <el-input v-model="form.insuranceAmount" placeholder="请输入保险金额" />
        </el-form-item>
        <el-form-item label="银行卡金额" prop="bankCardAmount">
          <el-input v-model="form.bankCardAmount" placeholder="请输入银行卡金额" />
        </el-form-item>
        <el-form-item label="支付宝金额" prop="alipayAmount">
          <el-input v-model="form.alipayAmount" placeholder="请输入支付宝金额" />
        </el-form-item>
        <el-form-item label="微信金额" prop="wechatAmount">
          <el-input v-model="form.wechatAmount" placeholder="请输入微信金额" />
        </el-form-item>
        <el-form-item label="信用卡金额" prop="creditCardAmount">
          <el-input v-model="form.creditCardAmount" placeholder="请输入信用卡金额" />
        </el-form-item>
        <el-form-item label="其他金额" prop="otherAmount">
          <el-input v-model="form.otherAmount" placeholder="请输入其他金额" />
        </el-form-item>
        <el-form-item label="审核操作员ID" prop="verifyOperatorId">
          <el-input v-model="form.verifyOperatorId" placeholder="请输入审核操作员ID" />
        </el-form-item>
        <el-form-item label="审核时间" prop="verifyDatetime">
          <el-date-picker clearable
            v-model="form.verifyDatetime"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择审核时间">
          </el-date-picker>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listOperatorSettleRecord, getOperatorSettleRecord, delOperatorSettleRecord, addOperatorSettleRecord, updateOperatorSettleRecord } from "@/api/bms/operatorSettleRecord";

export default {
  name: "OperatorSettleRecord",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 收费员日结表格数据
      operatorSettleRecordList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        startDatetime: null,
        endDatetime: null,
        createDatetime: null,
        cashierId: null,
        invoiceNum: null,
        rushInvoiceNum: null,
        reprintInvoiceNum: null,
        startEndInvoiceIdStr: null,
        rushInvoiceIdListStr: null,
        reprintInvoiceIdListStr: null,
        medicineAmount: null,
        herbalAmount: null,
        checkAmount: null,
        dispositionAmount: null,
        registrationAmount: null,
        testAmount: null,
        amount: null,
        cashAmount: null,
        insuranceAmount: null,
        bankCardAmount: null,
        alipayAmount: null,
        wechatAmount: null,
        creditCardAmount: null,
        otherAmount: null,
        verifyOperatorId: null,
        verifyDatetime: null,
        verifyStatus: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询收费员日结列表 */
    getList() {
      this.loading = true;
      listOperatorSettleRecord(this.queryParams).then(response => {
        this.operatorSettleRecordList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        startDatetime: null,
        endDatetime: null,
        createDatetime: null,
        cashierId: null,
        invoiceNum: null,
        rushInvoiceNum: null,
        reprintInvoiceNum: null,
        startEndInvoiceIdStr: null,
        rushInvoiceIdListStr: null,
        reprintInvoiceIdListStr: null,
        medicineAmount: null,
        herbalAmount: null,
        checkAmount: null,
        dispositionAmount: null,
        registrationAmount: null,
        testAmount: null,
        amount: null,
        cashAmount: null,
        insuranceAmount: null,
        bankCardAmount: null,
        alipayAmount: null,
        wechatAmount: null,
        creditCardAmount: null,
        otherAmount: null,
        verifyOperatorId: null,
        verifyDatetime: null,
        verifyStatus: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加收费员日结";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getOperatorSettleRecord(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改收费员日结";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateOperatorSettleRecord(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addOperatorSettleRecord(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除收费员日结编号为"' + ids + '"的数据项？').then(function() {
        return delOperatorSettleRecord(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('bms/operatorSettleRecord/export', {
        ...this.queryParams
      }, `operatorSettleRecord_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
